
package com.probiz.estoremf.customer.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.Constants;
import com.probiz.estore.common.model.product.Product;
import com.probiz.estore.common.model.product.StockNotify;
import com.probiz.estore.core.controller.GenericCustomerFrontController;
import com.probiz.estore.product.service.ProductManager;
import com.probiz.estore.product.service.StockNotifyManager;
import com.probiz.estore.webapp.util.RequestContext;
import com.probiz.estore.webapp.util.RequestUtil;


public class CsStockNotifyFrontController extends GenericCustomerFrontController<StockNotify> {

	private StockNotifyManager stockNotifyManager;
	private ProductManager productManager;
	
	public void setStockNotifyManager(StockNotifyManager stockNotifyManager) {
		this.stockNotifyManager = stockNotifyManager;
	}
	

	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
	}


	@Override
	protected void initController() throws Exception {
	}
	@Override
	protected String getEntityName(StockNotify entity) {
		return null;
	}
	@Override
	protected Map<Integer, Map<String, Object>> getMultiSaveModel(
			HttpServletRequest request) {
		return null;
	}
	@Override
	protected void preSave(HttpServletRequest request, StockNotify entity,
			BindException errors) {
	}
	
	

	/**
	 * 查看缺货登记列表
	 */
	public ModelAndView defaultAction(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csStockNotifyList");
		List<StockNotify> stockNotifyList = stockNotifyManager.getByCustomerId(RequestContext.getCurrentUserId());
		mv.addObject("stockNotifyList",stockNotifyList);
        return mv;
    }
	/**
	 * 删除缺货登记
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView deleteStockNotify(HttpServletRequest request,HttpServletResponse response) {
		Map<String, Object> data = new HashMap<String, Object>();
		stockNotifyManager.deleteById(RequestUtil.getInteger(request, "stockNotifyId"));
		return getModelAndAjaxJsonView(data);
	}
	/**
	 * 填写缺货登记
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView sign(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/csStockNotifyForm");
		Integer productId = productManager.getProductIdByUri(request.getRequestURI());
		Product product = productManager.getById(productId);
		mv.addObject("product",product);
		mv.addObject("customer",RequestContext.getCurrentUser());
		
        return mv;
	}
	/**
	 * 添加缺货登记
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	public ModelAndView addStockNotify(HttpServletRequest request,HttpServletResponse response) throws Exception {
		Map<String, Object> data = new HashMap<String, Object>();
		StockNotify stockNotify = new StockNotify();
		bind(request, stockNotify);
		stockNotify.setCustomer(RequestContext.getCurrentUser());
		stockNotify.setInformStatus(Constants.FLAG_FALSE);
		stockNotifyManager.save(stockNotify);
		return getModelAndAjaxJsonView(data);
	}


	
}
